package de.tabuma.shopping.controller;

import de.tabuma.shopping.logik.*;
import de.tabuma.lib.*;
import de.tabuma.shopping.entity.*;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.google.appengine.api.users.*;

/**
 *
 * @author $Author: alefen $
 * @version $Revision: 1.2 $
 * @since $Date: 2009/07/21 19:37:32 $
 */
public class licenseAgreement extends tabumacontroller {

    private static Logger log =  Logger.getLogger(licenseAgreement.class.getName());
    String orderNav;
    String url;
    LicensePackageFacade licensePackageFacade;

    public licenseAgreement(String servlet, Hashtable parameter, String orderNav, String url, LicensePackageFacade licensePackageFacade) {
        super(servlet, parameter);
        this.orderNav = orderNav;
        this.licensePackageFacade = licensePackageFacade;
        this.url = url;
    }


    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response,PrintWriter out)  {

        details detailsController = new details(this.getServlet(), this.getParameter(), orderNav, url, licensePackageFacade);

        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        if(request.getParameter("Agreement")==null) {
            String orderLicenseErrorMessage = java.util.ResourceBundle.getBundle(de.tabuma.shopping.constants.projectLanguageBundle).getString("orders.licenseagreement.error.message");
            request.setAttribute("orderLicenseErrorMessage",orderLicenseErrorMessage);
            request.setAttribute(this.orderNav,de.tabuma.shopping.constants.ORDERNAV_LICENSEAGREEMENT);
            return;
        }
        int id = CurrentOrderFacade.createOrder(user.getEmail());
        request.setAttribute(this.orderNav,de.tabuma.shopping.constants.ORDERNAV_DETAILS);
        request.setAttribute(de.tabuma.shopping.constants.ORDER_NR,""+id);
        detailsController.navigate(context, request, response,out);
        return;
    }

}
